use core::fmt::Debug;

use evm_storage_verifier::{verify_account_storage_root, verify_storage_proof};
use gnark_mimc::new_mimc_constants_bls12_377;
use linea_light_client_types::{ClientState, Header};
use linea_types::account::ZkAccount;
use unionlabs::{
    ethereum::slot::{MappingKey, Slot},
    primitives::{H256, U256},
};

#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum Error {
    #[error("invalid rollup contract proof {0}")]
    InvalidRollupContractProof(evm_storage_verifier::error::Error),
    #[error("invalid l2 block number proof {0}")]
    InvalidL2BlockNumberProof(evm_storage_verifier::error::Error),
    #[error("invalid l2 timestamp proof {0}")]
    InvalidL2TimestampProof(evm_storage_verifier::error::Error),
    #[error("invalid l2 state root {0}")]
    InvalidL2StateRootProof(evm_storage_verifier::error::Error),
    #[error("invalid l2 ibc contract proof {0}")]
    InvalidL2IbcContractProof(linea_zktrie::verify::Error),
}

// 1. assert rootHash(rollup) in l1StateRoot
// 2. assert rollup.currentL2BlockNumber = l2BlockNumber
// 3. assert rollup.currentL2Timestamp = l2Timestamp
// 4. assert rollup.stateRootHashes[l2BlockNumber] = l2StateRoot
// 5. assert rootHash(l2IbcContract) in l2StateRoot
pub fn verify_header(
    client_state: ClientState,
    header: Header,
    l1_state_root: H256,
) -> Result<(), Error> {
    // 1.
    verify_account_storage_root(
        l1_state_root,
        &client_state.l1_rollup_contract_address,
        &header.l1_rollup_contract_proof.proof,
        &header.l1_rollup_contract_proof.storage_root,
    )
    .map_err(Error::InvalidRollupContractProof)?;

    // 2.
    verify_storage_proof(
        header.l1_rollup_contract_proof.storage_root,
        client_state.l1_rollup_current_l2_block_number_slot,
        &rlp::encode(&header.l2_block_number_proof.value),
        &header.l2_block_number_proof.proof,
    )
    .map_err(Error::InvalidL2BlockNumberProof)?;

    // 3.
    verify_storage_proof(
        header.l1_rollup_contract_proof.storage_root,
        client_state.l1_rollup_current_l2_timestamp_slot,
        &rlp::encode(&header.l2_timestamp_proof.value),
        &header.l2_timestamp_proof.proof,
    )
    .map_err(Error::InvalidL2TimestampProof)?;

    // 4.
    verify_storage_proof(
        header.l1_rollup_contract_proof.storage_root,
        state_root_hashes_mapping_key(
            &client_state.l1_rollup_l2_state_root_hashes_slot,
            &header.l2_block_number_proof.value,
        ),
        &rlp::encode(&header.l2_state_root_proof.value),
        &header.l2_state_root_proof.proof,
    )
    .map_err(Error::InvalidL2StateRootProof)?;

    // 5.
    linea_zktrie::verify::verify_inclusion_and_key::<ZkAccount>(
        &new_mimc_constants_bls12_377(),
        header.l2_ibc_contract_proof.leaf_index,
        &header.l2_ibc_contract_proof.proof,
        header.l2_state_root_proof.value.to_be_bytes().into(),
        client_state.l2_ibc_contract_address,
    )
    .map_err(Error::InvalidL2IbcContractProof)?;

    Ok(())
}

pub fn state_root_hashes_mapping_key(slot: &U256, l2_block_number: &U256) -> U256 {
    Slot::Mapping(&Slot::Offset(*slot), MappingKey::Uint256(*l2_block_number)).slot()
}

// #[cfg(test)]
// mod tests {
//     use hex_literal::hex;
//     use linea_light_client_types::{ClientState, Header};
//     use unionlabs::{ibc::core::client::height::Height, primitives::U256};

//     use crate::{state_root_hashes_mapping_key, verify_header};

//     #[test]
//     fn test_state_root_hashes_slot() {
//         assert_eq!(
//             U256::from_be_bytes(hex!(
//                 "88223631b07ce89e56b26e6825547f018d754fc79f5331cda31396a6be7d2d18"
//             )),
//             state_root_hashes_mapping_key(&0x11A.into(), &620681.into())
//         );
//     }

//     #[test]
//     fn test_verify_header_for_update() {
//         let client_state = ClientState {
//             chain_id: 59144.into(),
//             l1_client_id: "08-wasm-0".into(),
//             l1_latest_height: Height {
//                 revision_number: 0,
//                 revision_height: 0,
//             },
//             l1_rollup_contract_address: hex!("B218f8A4Bc926cF1cA7b3423c154a0D627Bdb7E5").into(),
//             l1_rollup_current_l2_timestamp_slot: 0x118.into(),
//             l1_rollup_current_l2_block_number_slot: 0x119.into(),
//             l1_rollup_l2_state_root_hashes_slot: 0x11A.into(),
//             l2_ibc_contract_address: hex!("5ff137d4b0fdcd49dca30c7cf57e578a026d2789").into(),
//             frozen_height: Height::default(),
//         };
//         let header = Header {
//             l1_height: Height {
//                 revision_number: 0,
//                 revision_height: 4946965, // execution: 5855907
//             },
//             l1_rollup_contract_proof: serde_json::from_str(r#"
// { "storage_root": "0x26a5ca50671f3feb7abdd10c729ee5136358dbaf56be37707a1e7da25ba2cb34",
//   "proof":
// [
//   "0xf90211a0b11e984749d4ccd017ae0c73dcf99d86e40e8f0c540d61fd0d2ce5dd2672c1fba01ea2fac8a9b993dd5dec96242d537bf5b0889d8f316511531d639ff04827b7f5a0aefdd2554317f7d23c87dfd47b73f8009baddaf5fb114a0283c63f08a1c85129a03d6f0dc8eb7e0411d8815d14cfd577a055b5dee1fccf31d2371ec79faf8ae867a05fd28375c20b110411da39937fcbb09b8ea7f80b5b022bb24ccfac066dabce0ea0ab4560a07a8c1f853e994612ca764c33beda4464a0f39af212e638c07e04f5c0a0a9e656be287f7b04936a27bad4442f5ae947dd89f0aab9007c771805028f93b6a0cc5d3ca43597c4e80177521c2ae84f62c02afc7ee5bd5d5212b64b200908268ba044242cbc18d9b49966c1855abe98510690c51cdf1d7b9a0541ca35dad8204d22a0057439c38fb1db95c9d41e866d6a11ce9d755ade35c8d8424863ae4eabbe7d66a0dd24caf98fd107f873f6dfee85c0c41a3d76bc86da2cc8eed391f85420d86adaa0103e2876a267f87549762643b0d7381d1d8466a9f9d2aab495c84a05129478f2a0a435a3c7a7a4d84e537f6d57bd8f63c1ecb3953d4b7bda3fb2b776a16adc02bea0170168f226ac9aff7cbc895a95aca034ca50de4e9f298f934aa0349cfef283f3a06af3e817abd010e0156449ae86b5e754d2f86421b8badaf7eab99227ffe4f023a0817e202fc3cfd4539f39a61f3ba8a9a1a3ade5c30743eed1e7c589e7ef55d7dd80",
//   "0xf90211a0c279f69587929e075408586adcc0ef440c6c7aadfa99ea5d02bb4267e8887f8da050c123139b102649a94242b4622b76b09eb388df72360a700cde9a616ca204f7a0ee5871574c14b7bc1b98e4e809815015ebdebcf19824a32d2a1e424707a72713a01eedfd222f7fdb29262129ca7c252e9bf51c42363a35a616eae34c3eab65f675a0d6db2e197a2f3bb0c1789d6b6c98c8d1628ded03da9d55bb90c27669365a29aea0c95f1a8912300179c5004aea03f82608317bf4d8867a68d0b0b3c1e855a897b6a076340ee77efbf74432a5357e4261a9ee07e0bce0802be5fc0e3ca84f68216c19a095c7031bc4c722c5668898036943f13f006af9c3891d604339e7d1e989a07fa9a0af54a98fc1f02568277cd3e7c660e1ee8d45ede737cdaa238dd5c1362ebc03bea0696778038869da674829b3db8ae10f8653da9241daa00310ad7e6c4687cc04d4a098f56999331323727b97de1fdc52903052728e5299a3eae911ce92d0bacc9090a0325a2a5bd2c0355360dd924c8bc415364fc83cdef7e8f30ebb391c6bbb774382a04569f40a8b68708346ca2ab838cbbe9f77abf1bf81915bf8ac53a7a5f72094e7a03595e3636430b8171a9eb176e8c9785c86ce1cc3646bfb9a34a7b36380d6de40a0089b29e3dbeac038c949f34ae0ca5a4b8c6fcc28c4cced34f01ab7c045fdf5fba0f53d5d8f6b13513db96dc843d2d42626b3398eb59bc5e195a86b7022a6973d7080",
//   "0xf90211a0110be87dcb360c2d8eeed57453d1d28f0b18a859f00c3a1c9adef0b18cce5183a00237b5e1311c0394c98ced835efebd26466845dd263c512b1beae0372f0cfe2ba014d6e41046fcdac0f53b2b6708e21bf2699d5f3176235420c89b25928e9f2931a007dc242c02eb666f81740156314f95a11cb9d5788dee5bae25f5380d29a926bda0b250c9db115d492ef814650a188a4b34b5aa1d71f14f4b49f07ac459deb0a8f2a015ca94bdb7a0b7ea355cc4fc388fddc7aae8a00b88c0a8d5051d0eb0892af619a0cd59ac92bd17b99a9bba788609f2ea4b3c0779f6c4b74925eb33b374d82b62d7a03b94b825fb14c8f2c7f5a82899baab8aba504225a173626e801b8913f91f20eaa0f4ab579e81c17d19afb6a5065d2aea1a5ae97bc7fb311354f27c83eb874f77eea0c4966ffbf4ef4a721512140d26e063ef588a6becba36dfd433658be8f3908eb7a0be7b48cc2f317beb2698188aa6ab7fe510f9a0de2d319bcec581edab1d4408b3a0292617c565260e1367e8d3478d5ed5f9c7e2110a151b7ff90106ce05e6b1d850a00613087c563f9f63996c41f76331567cdc250f1290bf030fa4903c650583b544a069578db2bda3992ac7a6f210e27ea7a66ef03d7cd34126ad8d287df69d241827a0d94604242d20bf124624bfbeb7fac8dcfe63d05ab1d4b21e94facd99d5a0124ca065322738ae4cff82e970caea7c8aed21413fa39c9bed706b071968569508c07380",
//   "0xf90211a0367d55701083ad3c06e14a3265244d4dcdaa3a7a236cc7a3c539c1879e761714a0994dbc61cb0f7987987198657ce5e43f342f517cdfa34be82745dba7a74c34cca09408026912c4e8ca608c97e57db85d671e682a894f03b5e822f55e7cbe99eb91a07cabd1c6a4f6cd84a3126f8f08cd4878c72e17ad5b7d66d44a60d7148e916a18a095ec1667475fd39aab1344ddec8a67b0c50b1998290e7ff160c9ce43b84d3553a03ee889f507b105cfc28e50529678f5f0c76e0f0a96057f02c00918c6293de9b9a041ddd0c6b81605a8d2baf7dac505079b01cca0b5a50c2c95cb8d0e0170650215a0e2be93ad2924a6438cac312b761cbf65a848b48b4a5f64c69d6f3fdae8e2084da0bc51dcbb421b905ed99af111c891fe319bdb04b2377dd611a6ca3fb57e09fbc5a0b6b0630f576c0a6623de8d4d597d996611c7da72e2e2a8bbf00b69ae620335cfa09b845dfc319b8c4bdbb69bef557c9ee4d562de393e2fbaf77bd44a37924ca5eca05c1d2b6a037615d7b6a45c2f80f48e052358cbeefca40d59a8bece27398596bfa07a0c52d765e89fb0d2a91880a91d6c7780402a88a9672739e3e401fef1019512a0364de1036ba088b2f474368f46bac9ee90d56c194d4ac848d373c5ce56dfa38ca089d514fd746c9959682aedf104b7b995a04cc4410e3d541ac2967ff3f8917db0a0338de52007d4771cb77c0c5d282222e669b12f5b14ac0e3249757e605c451ea180",
//   "0xf90211a07ca582d2791e541b2c6f5b1c0827d004765a1a980672ccd03d24e7637c67cdfda040a762b1c9a3652905b0c7868a7c0039a0b762979cecedbb277149561f7534e4a04a014f2dff50f8f996168959f1710d32371cb75d5199621c160752080f54fd65a04f285e4e947cc23771dba016eac91ece045295b314967b53ba0ae6aae235c2e3a0a7479a4d12796bc8f9e835521d450c9a8f3aa791d27ec5da7b5ca6b66e295ee5a03f9efcf9f44daf0e04dc9f4bf63cf7487bafe4286388de436e007ddd273c86aba09f3ec2a1a5cf8eb51a9beeba044f6d960aa820a8313603e00ec0ae7c861112eca02abaae7bcd0190ce014da98b5c5823aadb8212962585492c6b6fae97e83fe29da0c4aa31957084f3d53324629fb161c08e4ab79099f88d2e04d7bafdfd8fbe8908a04d4f794b1313d7395f61eec500542267198a5543ceffcf024ee703cf8516083ba09dfb90468ddd0f817f969158ee39e0debccb02ac2dd36b0bd4eb59097f025cfca03334485d283b726a859b32470cb8ef9b165dd29426176de76199abe6ff3a7f4ba0ee47dfd208abf5090cdfe7830534c89b9e475fc3d9465a329542890035aedd5aa0791716168bcf00ac95285b6575e2cc99b246a2e75903a942170ea06e8379321fa0120138d26438214f82c74e6304ae1d2d0d9f95ad8f9107300433b1636826ed0ea0ec820e8429e67c58d3ac8c75a5a1e450c3c3b72f6b08311c3e8f405e537e229780",
//   "0xf901718080a0041da6a310753cad27ffab806c70ce10258fd79be61e766f9982689c5d45aad1a0c1601f7f6112727c153f9b5edae3d10b0c1fda3ca0999c2bbe5f910f72d65f56a0ff32ac535390cfdd1d26359e3e955331735de77e51bce1a4c5f1446a06e0b59ca000a3ae4514eb3a2df1b208a2391a6aba8f8a7af7b912a9e471043ede15fc9adca0e039e5b9487ef5bf0a7cb5b4408fda00d92265fa8dd3be18afec511aaa119a6780a0b93abb1775d26ec583c7c4a6910358536995c63b2512b57ef66bae3f98f93e9680a000855288f93146cc24e985085f4d007d6e926c969dfeca97661a23cce6f19283a0d7df92278762ed35c2852147cbb4698eda8bcd51626092c088106d29c198af49a011f02f2cf8f0712589bda5c2b10d0d1574241b39f8c35c7eb20692f4ff1e459180a0bc26cfffd5783ed45750605e43bd566cd995d8de50ac8addc6288943a7b8f6dda0a0aa982d31e76c874b9a9d595179d3e05a9cd630570a0d9f62e2572730af10a580",
//   "0xf871a010d752f6f8c9313d414365d34e5bdb2633555f7f5319e4a5e901d817467aa6e580808080a0b0101b41cb7101e2bad95ee915a8482f08ad989040056b7943d4a9434d1971b3a0d59c6f9a0a6c333465ace018d65e94bf8fe4353966513b2fabb80ae612b444c480808080808080808080",
//   "0xf8709d35223643911a8560f041595427e2eec8d440b6fc322943840fb0d6936db850f84e018aee3df9a928ee5878c850a026a5ca50671f3feb7abdd10c729ee5136358dbaf56be37707a1e7da25ba2cb34a04d9be648c5bf39973670d9f8b481d5d0b971e6a2db2deccc6b98cde21c5dd83e"
// ]
// }
// "#).unwrap(),
//             l2_timestamp_proof: serde_json::from_str(r#"
//   {
//     "key": "0x118",
//     "value": "0x663a44ff",
//     "proof": [
//       "0xf90211a06bf01d38371674c390e78013c9fda058ea046dbe2e9cb2ce6960b39b31e09ceda07d2d75ba8b60e63033ef53f9599e177ac264ffb7872f333bc71db0c1b878decfa0a838d3057a3491f1c853a30d9ab019ca645bda6034b3d42ae7b8f4fb88ef2762a040943d7bee639787e1c50996c00fd5c556a1adbffaee0239cc24c1b71be502e0a0a23de6032143a31abb641b38c22c3c3cd3e6110348f38a73bc09088bbe7d497aa02d7096b6554a3f0dc1d867bc9987d70f2a39736266b62bcaf7cc801719b1572ea02e069fac56817d4600665a06e28180634a14ffd9b766c33a97d76e43578c0a40a032b0f4f958cc4493b525b6c479e9d5b3d0478a92b04376524e89ade502d8a1f3a044c75bcc0f7f21ba9d44b12416daaa21ef6f59312542c6587cca41f969c77214a09941064b101954a994f0e7df150f8a8deab44a30ebdb0164eb34e83e0130ba36a0241c793cbc66f18b1239e3753308bbd05f7703a11dfeb0e74a32d12f97e9a533a0d2b3a889dfb1fc25c2c0603749b901aac9e0158287e4071af3664903bf441270a030972bdbdc64a6089fd8a13293f8182921b9a1e39ee982eeabd1276b0ce17e29a06971c693d075b25d9686dd670bc0d62cbc2747eacba65f3b9c460e09f386d376a00179730a469043728be984e460d4348f92e59c494b2cae8f62fa887dea5e5c84a090c4c1b31dc8eb2193aa882822151ea4ef47854e4e9076c9b72e6b7fd459fef380",
//       "0xf90211a089ab735456e60f4475e87ed9b7db93557460dc6adce5b7b7f6ad69d69439b4d8a03545efdc5d50c3b712c91f8f9964af394a139baf2df4d33c0189ed0c5288a772a02fd7428b00e88857acb7b6ef1f537a6333513c6219d49de278f59fabbbfb2a81a038225cd8362fce6228cf894c343edd4905c9e3c4e9923c89f3de4fefe3af4c83a06e304aa57733d2bf2d40390b2c8c64a15b61275008add2bba3fab9f1fe585ac3a0faf3afc37ac7122a7b38b7b4e60f45b4b75a2eea0d51e143f15fed32aae9ce2da05c3e905a073bea2e6da0610bcded5fb3f068ab782c1b02976435ebb1aa1344fea083b7d1bf89365462551bd1f99b30d59b0e326c01a976436feda1deb9386c588ba0d15289e41f3bb3304a88df448d3789efeefd251b062c0272568eff8dd545800da0d3b606f95238a86a9010a25292891271695c697192e4527bf38c0627e3076031a032081178a8d5efe82876d9c75290a5896748b37222c3308440c71b660cb97386a061f95630acfed3dde77007f780d363a255964b0a8834902329a461b17bc712a1a047bf7361759b28635366f5ad2e9dc6d2116ea9470314a6a222c613e7be06cbc3a094daeee28a1f4bd29a05ffd2fc27c9e0d81207896b6b8c8dfcc80ab52c4f6a20a05b759cc27042e6ae7b93c6c24da1ceb4c21b86bd88262b45e2e5ca55af2c0b75a057f2896ccba7ee6ff374c437ff5889956e87fbced65cb6f32b157b6bc57d100a80",
//       "0xf901b180a01ee013723244fb3a0abe6990c0980ab4f76fd14bc85988c94b8a3a21517a570ea036d37b2e4f73ceadabdf80be5c1375e2c02dca5ef80a30c453fd2da301904d96a03c397fca525135a356765ab94fe45213ff3fd7233a10ad3cd2283949ca839765a08bfa0a753ffef7d73c3a7ca845c8162d11401bc61d1319f72115b762df070338a0e7ceaf1f47bb91a4f2e65aaabbfca2ae49f6c7a022e401e4527adb6e93a7d12ca041bc96608042f4cb2760fa48ac49460e40b14c147743c98790471464586235a4a02fcf6ecd3d005ae7d5dc32310aebd42e796a07f74f2241d3ae2ea512250513098080a0a08f97037a687da400f93378c867c4d5f8e92c3c75eb14d508aceed7f1c663eba0e6161cd08bca312d2ce1898e6f2900054307d2352344f5e4f829be4ea3c001a1a05bfc2f7d4025981389d2cb08418f8c0bd05c77b649c77bbfa5d84c2415a9d4b7a08e4367033feee0b42d5d130205eb648441e0ab381757be302e4bb92ae5836b7ea067c1a588cc7a45bc4615887100e209f5f81d28b01d7366413aa722eb1842d528a0840d08ff81fe1ba507942cdaba945c98dd3b6abad7258c22c0e91474fa8ef1ed80",
//       "0xf85180a05d70523347f1c1595d2be200fb34baa9921173218a1586fd73b6152bd56060138080808080a065734055c6762d4c50777cc0f480d41a480339ba87301bce2110b29025e6c06e808080808080808080",
//       "0xe69f20deb247cc158d01ecf635e1727d4c1ad65177ed51d3c365b299b8a5e12e248584663a44ff"
//     ]
//   }
// "#).unwrap(),
//             l2_block_number_proof: serde_json::from_str(r#"
// {
//   "key": "0x119",
//   "value": "0x97889",
//   "proof": [
//     "0xf90211a06bf01d38371674c390e78013c9fda058ea046dbe2e9cb2ce6960b39b31e09ceda07d2d75ba8b60e63033ef53f9599e177ac264ffb7872f333bc71db0c1b878decfa0a838d3057a3491f1c853a30d9ab019ca645bda6034b3d42ae7b8f4fb88ef2762a040943d7bee639787e1c50996c00fd5c556a1adbffaee0239cc24c1b71be502e0a0a23de6032143a31abb641b38c22c3c3cd3e6110348f38a73bc09088bbe7d497aa02d7096b6554a3f0dc1d867bc9987d70f2a39736266b62bcaf7cc801719b1572ea02e069fac56817d4600665a06e28180634a14ffd9b766c33a97d76e43578c0a40a032b0f4f958cc4493b525b6c479e9d5b3d0478a92b04376524e89ade502d8a1f3a044c75bcc0f7f21ba9d44b12416daaa21ef6f59312542c6587cca41f969c77214a09941064b101954a994f0e7df150f8a8deab44a30ebdb0164eb34e83e0130ba36a0241c793cbc66f18b1239e3753308bbd05f7703a11dfeb0e74a32d12f97e9a533a0d2b3a889dfb1fc25c2c0603749b901aac9e0158287e4071af3664903bf441270a030972bdbdc64a6089fd8a13293f8182921b9a1e39ee982eeabd1276b0ce17e29a06971c693d075b25d9686dd670bc0d62cbc2747eacba65f3b9c460e09f386d376a00179730a469043728be984e460d4348f92e59c494b2cae8f62fa887dea5e5c84a090c4c1b31dc8eb2193aa882822151ea4ef47854e4e9076c9b72e6b7fd459fef380",
//     "0xf90211a06e5dba711aefd578363a9ac6aee4afdf81408cab66be4d4faf533ddc12318e81a026e73fedba365b5ae575c12522ce6cc0ed3738d23dff488cb8685f834a2e5988a0f2699f0c4948954f47cba71bb49a4ce1741ffa524f8307db16ae854f4da7366ba009d94b8e05351eb893db1042d0c7b296c9cd868d9a66a0333873cc302c830163a0a998eeb9b9a2e6e240ff56e6576b717860e54a23ea1392d499321dddf56c3911a04ba0b2de22b692e2cdc492fc6f110be0a2231597469dcafa459619f888f4ca2fa07e72b76f6348005bbb7ef4646f45b2406d681c011f060fe445813025aa791570a06fb27e4ce4304c70b60e6169adc718e3ddd581b539d073ae7b1a87598d9ebdeca0efb05a9ff794077f6331b44ecfbc52f283d40dc722d314c60462e206f5d5c5e9a068b5ad36f5d4576a8fe64f8582993914045ad85d109c4ddc75ab9a43c93942efa0de2e2bf4a86537681d19c2dce8abdfea970f6bd522da5869f2a00234556fcfc2a0be41f0517b378ea2bd1c6b756550e552cc0d2b3b9c88d6a9929b874571fd9140a0af56419aa347dda35c5bab7aa90a7a79d0c0aece0cc1b2605068805e39fe2db0a087210615efb7f7bcb1f0503e51ac91814647bd9824115c48c9954f572bd2c9cda0e25b667f9f6b5f2adbfc2e8fb663f57630ec266485230037ae4f67016f85e9eaa096e82e854f880308aa570683c9118b4faf862feaec037039320df7c12d51a74480",
//     "0xf90191a09d6f2414cab5d257d3b60573131bd32080c6f7dd8d9e497a05ffe97d7407fde3a0efa7a1cd52783cb6efb8e31fca4ff738638d9f06fd5969586b3717feb79d5b29a0ba902d490d534a954f14bffe063005c13791ec71e8121347ab4b6afa62030517a05ef6b6ea93979aac5bc7e3d9af38673533e31f831c0811cf435c670cb90748a2a04d45ba907e527c4a47cfd60eaf0706148175717e70a5bcf073ee8b4222554765a035501b458f5617e8d43c159cbfae78d7afce9862db2a1b894f29cd997553ff8ea09da5fd230d0e7d479dc4f790b61a34dd1fc6df34fdfcfa18d81a25d11e6472158080a0c908c6530c2a5a8c21e086655ef777e2b8d354bf1545c5496b66eb134cb1a694a0e9dd6a55f2f25fc8f049e94183b436d2dc19821a033f1f802c17b2f428269680a0ea5b9312ed76cc2f9674481299140cb4677c4652998e89a5a4a02766ec6d2638a00e0f73b31600408c573d7d6c34f56ddb4d0c0f1c7c500a037d29318333ad876680a03b05bd8acb4cda93f7af23de99a1d2b5ceff1c45937dd6256d272fcce325bcf98080",
//     "0xf85180808080808080a0553ac3ce806a18d3843296a9e20adb0cd9754e0a8294d19e0b367fe5d3ccbc28a04ebb7b65bee39683047a9426b0b5184e22c90a09b590da93ec91f04feceff4088080808080808080",
//     "0xe59f201a1c59257d882f21f6b09f2a6b260448d35f58469939b33d8124d4e43de18483097889"
//   ]
// }
// "#).unwrap(),
//             l2_state_root_proof: serde_json::from_str(r#"
// {
//   "key": "0x88223631b07ce89e56b26e6825547f018d754fc79f5331cda31396a6be7d2d18",
//   "value": "0xc76548458cc04a5aa09bffa092b32c912aee635c1c44364ebb911286a10263d",
//   "proof": [
//     "0xf90211a06bf01d38371674c390e78013c9fda058ea046dbe2e9cb2ce6960b39b31e09ceda07d2d75ba8b60e63033ef53f9599e177ac264ffb7872f333bc71db0c1b878decfa0a838d3057a3491f1c853a30d9ab019ca645bda6034b3d42ae7b8f4fb88ef2762a040943d7bee639787e1c50996c00fd5c556a1adbffaee0239cc24c1b71be502e0a0a23de6032143a31abb641b38c22c3c3cd3e6110348f38a73bc09088bbe7d497aa02d7096b6554a3f0dc1d867bc9987d70f2a39736266b62bcaf7cc801719b1572ea02e069fac56817d4600665a06e28180634a14ffd9b766c33a97d76e43578c0a40a032b0f4f958cc4493b525b6c479e9d5b3d0478a92b04376524e89ade502d8a1f3a044c75bcc0f7f21ba9d44b12416daaa21ef6f59312542c6587cca41f969c77214a09941064b101954a994f0e7df150f8a8deab44a30ebdb0164eb34e83e0130ba36a0241c793cbc66f18b1239e3753308bbd05f7703a11dfeb0e74a32d12f97e9a533a0d2b3a889dfb1fc25c2c0603749b901aac9e0158287e4071af3664903bf441270a030972bdbdc64a6089fd8a13293f8182921b9a1e39ee982eeabd1276b0ce17e29a06971c693d075b25d9686dd670bc0d62cbc2747eacba65f3b9c460e09f386d376a00179730a469043728be984e460d4348f92e59c494b2cae8f62fa887dea5e5c84a090c4c1b31dc8eb2193aa882822151ea4ef47854e4e9076c9b72e6b7fd459fef380",
//     "0xf90211a06e5dba711aefd578363a9ac6aee4afdf81408cab66be4d4faf533ddc12318e81a026e73fedba365b5ae575c12522ce6cc0ed3738d23dff488cb8685f834a2e5988a0f2699f0c4948954f47cba71bb49a4ce1741ffa524f8307db16ae854f4da7366ba009d94b8e05351eb893db1042d0c7b296c9cd868d9a66a0333873cc302c830163a0a998eeb9b9a2e6e240ff56e6576b717860e54a23ea1392d499321dddf56c3911a04ba0b2de22b692e2cdc492fc6f110be0a2231597469dcafa459619f888f4ca2fa07e72b76f6348005bbb7ef4646f45b2406d681c011f060fe445813025aa791570a06fb27e4ce4304c70b60e6169adc718e3ddd581b539d073ae7b1a87598d9ebdeca0efb05a9ff794077f6331b44ecfbc52f283d40dc722d314c60462e206f5d5c5e9a068b5ad36f5d4576a8fe64f8582993914045ad85d109c4ddc75ab9a43c93942efa0de2e2bf4a86537681d19c2dce8abdfea970f6bd522da5869f2a00234556fcfc2a0be41f0517b378ea2bd1c6b756550e552cc0d2b3b9c88d6a9929b874571fd9140a0af56419aa347dda35c5bab7aa90a7a79d0c0aece0cc1b2605068805e39fe2db0a087210615efb7f7bcb1f0503e51ac91814647bd9824115c48c9954f572bd2c9cda0e25b667f9f6b5f2adbfc2e8fb663f57630ec266485230037ae4f67016f85e9eaa096e82e854f880308aa570683c9118b4faf862feaec037039320df7c12d51a74480",
//     "0xf901b1a02cfbec8dcde4f856780bbf714a7c43c6861adc60eaa34fdcaf037110bbcce51080a0b4fdc18df9506854a2bd324195e2aa727a9c44ff4dbebef7075e2de678e8bec1a04e77bac714fa0b88d2511404cd4c1b15274ee47f1be037bda1cb149732df853ba057346b926ba66b7cb8ed9c9b5edaebebda535d5d022de0e72ea0db377e5780b8a0990801aa1e6b66bb0be3c9470d725d77bd67e6d71a24483783fea6fae3b40f17a0bab9ce9cf2b97c5203f57bdbd0d7090db637160346b42e9aabeb345fd42b04d3a00a4fa4432cfb8b6b41ece4ea07d7401dec5897cb7929278749a6d79c84d1aad880a09dd78a91e3ba790f08f03f00b5de94908ed4d5949fa8351bd38ab99814f374ffa04e1bfca4c175178002cad1c648df8131d4432cf100e5e780cd499e388183c8f080a063475a0150e7d86f30318dfe1573b2b3f65bbe7a7473b11a3874f747042af390a0a20e809c9d1623a39332af33557d797b64dd629a87ee916d8f39515009dbad16a085c10e3aa70b22c7e1ef3e7db13ceb11ed98b4ef20988dbb3b13a1db6325e9a3a0d3f65a6a973adbfd7f4bf96b3c41d2bd39af84c99cf87e812db8db22d2390e2e80",
//     "0xf871a0c2356c0aa042be156f6257cbc1f83ad9a26f21d379e97c4ef3690ad4f85e18ac8080a006b3d22451ef66415bd75c97b806ada453cb35a88e3edfca995425e8d925841f8080808080a0003d8298a040a91fb79d5a2d30da0f288720ebb83a3154dca33dbc0a2d823a3680808080808080",
//     "0xf8429f208c6e48a1cab8aedea718bdd632b319f4a1810dfda510f0ba1824e1dab1e7a1a00c76548458cc04a5aa09bffa092b32c912aee635c1c44364ebb911286a10263d"
//   ]
// }
// "#).unwrap(),
//             l2_ibc_contract_proof: serde_json::from_str(r#"
// {
//     "key": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789",
//     "leafIndex": 65362,
//     "proof": {
//       "proofRelatedNodes": [
//         "0x00000000000000000000000000000000000000000000000000000000000120fe0393507c456718a986386c7923fe68b87c29d83ac7f7ce1cdb49afc7e66a4771",
//         "0x008a47a2a53dd5183a2dc127c399a004e2a6c7e60f73e104d7d79e6a2bd7e809008a47a2a53dd5183a2dc127c399a004e2a6c7e60f73e104d7d79e6a2bd7e809",
//         "0x060f08aed06ffb90efc9705dc38d37a7000da1add99cef1b8a84b9e72e7c8b7b060f08aed06ffb90efc9705dc38d37a7000da1add99cef1b8a84b9e72e7c8b7b",
//         "0x0a06dc31ae8e893bca0a076decb8c0caa9036b5f394abf79d7956411eef322550a06dc31ae8e893bca0a076decb8c0caa9036b5f394abf79d7956411eef32255",
//         "0x01f35ef342eaa841ee4306d38f2a1adeafe8967d23c31fe1a379b9a69353da6d01f35ef342eaa841ee4306d38f2a1adeafe8967d23c31fe1a379b9a69353da6d",
//         "0x090d53176fd185da729d0d68e0c0e646ef148f15864685f4ba56be7b7cbb2484090d53176fd185da729d0d68e0c0e646ef148f15864685f4ba56be7b7cbb2484",
//         "0x11c8e229e3e2ae40a4959e036d500753aaedb52cda67d9caf60f0629f0b4f30611c8e229e3e2ae40a4959e036d500753aaedb52cda67d9caf60f0629f0b4f306",
//         "0x07f048ac696418580a55a864a10ed030871fd615d5ab460c54d6184c16441d4807f048ac696418580a55a864a10ed030871fd615d5ab460c54d6184c16441d48",
//         "0x0f5dc218160db17cfe8044d7ac4fd55dfcbdf2676815e2c15388f189bf144cd80f5dc218160db17cfe8044d7ac4fd55dfcbdf2676815e2c15388f189bf144cd8",
//         "0x0cdf7d06a4b4b0e71713048f5f6ea86016467e909a27bfeeeca67b56c17e27390cdf7d06a4b4b0e71713048f5f6ea86016467e909a27bfeeeca67b56c17e2739",
//         "0x014030b5cbe31660da2d33b6b1265b82bbde9a7ab7f331f8b274f2b798a45a3b014030b5cbe31660da2d33b6b1265b82bbde9a7ab7f331f8b274f2b798a45a3b",
//         "0x11c8aeb3dc3ca059a29ba20d4471b20987d74a0d79ff8ecda247df6a02eca55411c8aeb3dc3ca059a29ba20d4471b20987d74a0d79ff8ecda247df6a02eca554",
//         "0x1092d1b2349c4fbc88ea0202cf88685e4e316c99697063f786201b27d46e2c221092d1b2349c4fbc88ea0202cf88685e4e316c99697063f786201b27d46e2c22",
//         "0x0969f4e85b86f0eb36ad13dfb1f35346d7d6518308dc27e73452c649850f1a890969f4e85b86f0eb36ad13dfb1f35346d7d6518308dc27e73452c649850f1a89",
//         "0x079081f446c9a0c7b404834742cea1909426ccfc4696d19e1a08531b0cc30368079081f446c9a0c7b404834742cea1909426ccfc4696d19e1a08531b0cc30368",
//         "0x004d50e626bda007887a31f60883e58bce50a1a3e7a3384b9ec18dab319dd458004d50e626bda007887a31f60883e58bce50a1a3e7a3384b9ec18dab319dd458",
//         "0x0b2ae68e3af633dac72090cc9c9b0dce76cebf5117101a265f54b3b9a851b3cd0b2ae68e3af633dac72090cc9c9b0dce76cebf5117101a265f54b3b9a851b3cd",
//         "0x0b7a8a9fe0ee619c9bd7ff504dcb47bdce0193546b53a79dedd5251f4f56f36c0b7a8a9fe0ee619c9bd7ff504dcb47bdce0193546b53a79dedd5251f4f56f36c",
//         "0x0defe934a1ae079cf6ec6022145b60128eeb30503eea4404da990fc2b2430ea80defe934a1ae079cf6ec6022145b60128eeb30503eea4404da990fc2b2430ea8",
//         "0x0e42718d49cb8c4be515181eda51f41d3b8198af5a2139a4670a8ee06b904a2b0e42718d49cb8c4be515181eda51f41d3b8198af5a2139a4670a8ee06b904a2b",
//         "0x1276c046afd611be02a66cf85498d7210a15293357afe07968a86c89356662f51276c046afd611be02a66cf85498d7210a15293357afe07968a86c89356662f5",
//         "0x02a9fd706c3c223f9374481b7495fb775c1675407556d93f1edabfe54b3fc9b202a9fd706c3c223f9374481b7495fb775c1675407556d93f1edabfe54b3fc9b2",
//         "0x070382f72e9f322433fb44fc4acfefd74b277b19b6cc1784379e7ca7338a2978070382f72e9f322433fb44fc4acfefd74b277b19b6cc1784379e7ca7338a2978",
//         "0x0133209cd7936e208da6b743428ff7195e8ef92d3dac72472146ac7497355ed10133209cd7936e208da6b743428ff7195e8ef92d3dac72472146ac7497355ed1",
//         "0x09cbd26c486bc2217bce59337120283f655a7ba65075f98059249f471812d0480b03678742039acaae14fd3964e2d6261b74410043c536f07bcf1bc4495d9f84",
//         "0x0c5c4d122720c4d6e7866d9b6bc6171c6259be90095976b665406ccf2dc6a8950305d7ebd7da4f82f061632eb7ec0c3060f51af848661d479bb64003f0fc5342",
//         "0x0c4762f6af9f09a529e70f0b34b7afafe2bba8944eccdcdb95cf13e0ff00ab2209d8b650f132967dba1764abe34c3d446311503ba7712d5f474a6e159b085b5f",
//         "0x0c3474a51e2654aca28b15add106ac676d92b9416ee788ac0b88873e77a009660176016fa85f1ba2375f784c72fae85763e12018e3e781c306f97ad9f826a22e",
//         "0x108459110262f154aef2d43fce77d314a7ec867f0068987716ff51582847e498009a6be6c408befa4eb7e6141fd427a2ce6489d50bf5f9de6bde9e100ada3482",
//         "0x118d3c53f9a3ea556029e867af93e9b4450cbacdf4dff29859e399ae16468e5102cefeff18d2980c8a9253c4609506472ba4764ea99efa6324dacf34740d9f05",
//         "0x005d88c799974510f99c04afdaba0f6b8f62edd55d8d89910009e148385a72c30a8fac91e2023660e8ac50ff082578361ba0901b16fe691f9b78044cbf6d1c4b",
//         "0x106f788c7d5990bec78f6c9cadd15604c99a8f1d56c875d324bb5ece63d83f3606694c69c43303aa1c614d60ed8fc66838f368b134cfc1ab00b6c83b2b5b3c8c",
//         "0x0ba8fdb8888982dde981f8e2cc9177c8c3ce0607661e113604e436951776de9c0b9ec8fec4b0696c73e04fd6bee4aa345633d23ef0c6bc4e4bbcf757af2677f0",
//         "0x0f5ae90881ea3398fd1a14fb83babc2335dfc4e6298aada1d827042d67dea48f0dee0a62e8ff86baddb091105d845c862089fe2f1963cd3798d636035da4d518",
//         "0x03d41bdb96726bf7f745784e42eef043c8b797f788d9720e36e460502e14c9fb0923e0e0228d2fe8619e30581e3e225d4e99e0daa011e15ac34c28fa30ea2989",
//         "0x11335bc4bf8a15d8c116cbdfe74242e80c7f60ac1a614d00f99fb9e1148126930502f7b7740708503e3858bc6df707cf4a1a751bcef3f2a5eb6eff9d8efa5cf8",
//         "0x0d60d90907794deaabe1e532a128e17ac94ec30339f3e367bc9ecd0aa40fd8b6009f71be21f99f29acd62b42787c99e5192646f808306fff0960ef5cd9a5ac16",
//         "0x0a6fd861ba25def420f5503fbbc4e0de2e54b4fbf0b22364e4a188eaf72ac58c02e49a2a28faca35409f471b4d981951aeabba2f091a427a2e88c53d1c7eeed3",
//         "0x0a93ecccd90368342584da9a8623e89a7a71d36f1da58d9874d50c045587138b0476d671e749bd2cd45fe416e1409caa22863f8cebdf926920a9f68b150d92d7",
//         "0x0821de61351452c22cf6bdafcd85be9a8cb3c2ad0af51f871d44221575785f9d12200803e31923cc68d6c9b906876643688e3a7ccb21264f933028b060564e4d",
//         "0x0000000000000000000000000000000000000000000000000000000000001c1e000000000000000000000000000000000000000000000000000000000000a354000036e661469dd70081ada16334d16a4049a124e261cd93def5fff88f85afda01b285fb7d6e0c7e05505a348777221f3c9fb491bbbbea4853e62e93f415efe7",
//         "0x000000000000000000000000000000000000000000000000000000000000894100000000000000000000000000000000000000000000000000000000000002db104a10331d6a854148a10b11c19cf2abae0412c9909ecefca54adc135ee57a950481fe75941093272afb1f8f76353afad6b89b1c19c383b07730c6f160b59243"
//       ],
//       "value": "0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000017d7498da306d2911280c3481d8b1510e16062ffaa631812c3ca53639329c1577354f0e4cd850dde1255c33de5e8c499e72ca1f49352847124c0dbfc30d0374d4d5d5e7cddb83c7ac93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e700000000000000000000000000000000000000000000000000000000000005c89"
//     }
//   }
// "#).unwrap(),
//         };

//         assert_eq!(
//             verify_header(
//                 client_state,
//                 header,
//                 hex!("4fa153a281bbf4c6d9667c8717d33a680c0849475f28acb9ead55dfa0e797e83").into()
//             ),
//             Ok(())
//         );
//     }
// }
